
package com.eworking.eim.service;

import com.eworking.eim.EIMConstants;
import com.eworking.eim.EIMManager;
import com.eworking.eim.util.EIMLog;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;

public class EIMChatService extends Service {
    
    /** 日志输出标记 */
    private static final String _TAG = EIMChatService.class.getSimpleName();
    
    private final IBinder iBinder = new EIMBinder();;
    
    @Override
    public IBinder onBind(Intent intent) {
        EIMLog.d(_TAG, "EIMChatService:绑定服务");
        return this.iBinder;
    }
    
    @Override
    public void onCreate() {
        super.onCreate();
        EIMLog.d(_TAG, "EIMChatService:创建服务");
    }
    
    @Override
    public void onDestroy() {
        super.onDestroy();
        EIMLog.d(_TAG, "EIMChatService:销毁服务");
    }
    
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (intent == null) {
            return START_NOT_STICKY;
        }
        boolean isBootStart = intent.getBooleanExtra(EIMConstants._IS_BOOT_START,false);
        if (isBootStart) {
            EIMLog.d(_TAG, "开机启动服务，需要登陆");
            EIMManager.getInstance().init(getApplicationContext());
        }
        return START_NOT_STICKY;
    }
    
    @Override
    public boolean onUnbind(Intent intent) {
        EIMLog.d(_TAG, "EIMChatService:解除綁定");
        return super.onUnbind(intent);
    }
    
    public class EIMBinder extends Binder {
        
        public EIMChatService getService() {
            return new EIMChatService();
        }
    }
}
